package com.yq.core.util;

import com.yq.api.dto.UserTO;
import com.yq.core.comm.Constants;
import com.yq.core.dto.UserDO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by yq on 16-5-26.
 */
public class UserDOUtil {
    public static UserDO toUserDO(UserTO userTO){
        if(userTO == null){
            return null;
        }
        UserDO userDO = new UserDO();
        BeanUtils.copyProperties(userTO, userDO);
        return userDO;
    }

    public static List<UserDO> toUserDOList(List<UserTO> userTOList){
        if(userTOList == null){
            return null;
        }
        List<UserDO> userDOList = new ArrayList<UserDO>();
        if(userTOList.isEmpty()){
            return userDOList;
        }
        for (UserTO userTO : userTOList) {
            UserDO userDO = new UserDO();
            BeanUtils.copyProperties(userTO,userDO);
            userDOList.add(userDO);
        }
        return userDOList;
    }

    public static UserTO toUserTO(UserDO userDO){
        if(userDO == null){
            return null;
        }
        UserTO userTO = new UserTO();
        BeanUtils.copyProperties(userDO, userTO);
        return userTO;
    }

    public static List<UserTO> toUserTOList(List<UserDO> userDOList){
        if(userDOList == null){
            return null;
        }
        List<UserTO> userTOList = new ArrayList<UserTO>();
        if(userDOList.isEmpty()){
            return userTOList;
        }

        for (UserDO userDO : userDOList) {
            UserTO userTO = new UserTO();
            BeanUtils.copyProperties(userDO, userTO);
            userTOList.add(userTO);
        }

        return userTOList;
    }

    /**
     * 回写用户信息
     * */
    public static void writeBack(UserDO userDO, UserTO userTO) {
        if(userDO == null || userTO == null){
            return;
        }
        BeanUtils.copyProperties(userDO, userTO);
    }
}
